<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/utilities/xajax/xajax_core/xajax.inc.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/gui/presenter/PresenterCreateUser.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php';
		
	$debug = FirePHP :: getInstance(true);
	$debug -> setEnabled(true);
	
	//Permite eliminar los notices
	error_reporting (E_ALL ^ E_NOTICE);
	
	$_SESSION['debug'] = $debug;
	
	$xajax = new xajax(); 
	 
	$xajax -> register(XAJAX_FUNCTION, 'clickCreateUser');
	 
	$xajax -> processRequest(); 
	 
	$xajax -> configure('javascript URI','../../../utilities/xajax/');
	
	function clickCreateUser($user) {
		//$user['firstName']
				$GLOBALS['debug']->log($user['firstName'],"primerN");
			    $GLOBALS['debug']->log($user['secondName'],"secondName");
			    $GLOBALS['debug']->log($user['firstLastName'],"firstLastName");
			    $GLOBALS['debug']->log($user['secondLastName'],"secondLastName");
	  			$GLOBALS['debug']->log($user['emailAddress'],"emailAddress");
				$GLOBALS['debug']->log($user['role'],"role");
				$GLOBALS['debug']->log($user['userName'],"userName");
				$GLOBALS['debug']->log($user['password'],"password");
		
		$presenterCreateUser = new PresenterCreateUser();
		
    	$UserCreation = $presenterCreateUser -> clickCreateUser ($user);
		
		$response = new xajaxResponse();
		
       
	
    	if ($UserCreation == false)
			$response -> assign("transactionResult", "innerHTML", 
				'<font size="+1" color="#FF0000">La operaci&oacute;n fall&oacute;</font>');
		
		else
			$response -> assign("transactionResult", "innerHTML", 
				'<font size="+1" color="#006600">Operaci&oacute;n exitosa</font>');
		
		return $response;
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registre un nuevo usuario</title>
<?php 
	$xajax->printJavascript("../../../utilities/xajax/"); 
?>
<link rel="stylesheet" type="text/css" href="../css/formsStyles.css"/>
<script src="../jq/jquery-1.4.1.min.js" type="text/javascript"></script>
<!-- include the Tools -->
<script src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script>
<script type="text/javascript">
	
  $(document).ready(function (){	  
	  //$("#content").load("../news/news.php");
	  //loading menu
	//  $("#lateralMenu").load("homeMenu.htm");
	  
  });
  
  
</script>
</head>
<body>
	<div id="formsContainer">
        <div id="title">Registre un nuevo usuario</div><br />
        <form name="user" id="user">
            <table class="formTable" cellspacing="0" cellpadding="5">
                <tr class="even">
                    <td align="right">Primer nombre</td>
                    <td align="left">
                    	<input type="text" name="firstName" size="32" maxlength="20" />
                    </td>
                    <td align="right">Segundo nombre</td>
                    <td align="left">
                        <input type="text" name="secondName" size="32" maxlength="20" />
                    </td>
                </tr>
                
                <tr class="odd">
                    <td align="right">Primer apellido</td>
                    <td align="left">
                        <input type="text" name="firstLastName" size="32" maxlength="20" />
                    </td>
                    <td align="right">Segundo apellido</td>
                    <td align="left">
                        <input type="text" name="secondLastName" size="32" maxlength="20" />
                    </td>
                </tr>
                
                <tr class="even">
                    <td align="right">Correo electr&oacute;nico</td>
                    <td align="left">
                        <input type="text" name="emailAddress" size="32" maxlength="40" />
                    </td>
                    
                    <td align="right">Rol</td>
                    <td align="left">
                        <select name="role">
                        	<option value="0">Seleccione un rol</option>
                            <option value="1">Administrador</option>
                        </select>
                    </td>                    
                </tr>
                
                <tr class="odd">
                    <td align="right">Nombre de Usuario</td>
                    <td align="left">
                        <input type="text" name="userName" size="32" maxlength="40" />
                    </td>
                           
                </tr>
                
                <tr class="even">
                    <td align="right">Clave</td>
                    <td align="left">
                        <input type="password" name="password" size="32" maxlength="20" />
                    </td>
                    <td align="right">Confirmar clave</td>
                    <td align="left">
                        <input type="password" name="confirmPassword" size="32" maxlength="20" />
                    </td>
                </tr>
            </table>
            
            <div id="transactionResult" align="center"></div>
            
            <br /><div id="buttons" align="center">
            	<input type="button" name="buttonCreateUser" value="Registrar" onclick="xajax_clickCreateUser(xajax.getFormValues('user'))" />
            </div>
        </form>
    </div>
</body>
</html>